package com.chen.common.exception;

/**
 * @author chenzy
 * @since 2023/3/10
 * 该异常默认不打印堆栈信息.
 * 构建BaseException对象时,额外传一个Throwable对象给super,即可打印堆栈信息
 **/
public class BaseException extends RuntimeException{
    public final CodeThrow code;

    public BaseException(CodeThrow code, String msg, boolean fillInStackTrace) {
        super("[" + code + "]" + msg,fillInStackTrace?new RuntimeException():null);
        this.code = code;
    }

    public BaseException(CodeThrow code, String msg, Throwable e) {
        super("[" + code + "]" + msg,e);
        this.code = code;
    }

    public BaseException(CodeThrow code, Throwable e) {
        this(code,code.msg,e);
    }

    public BaseException(CodeThrow code) {
        this(code,code.msg,false);
    }

    public BaseException(CodeThrow code,String msg) {
        this(code,msg,false);
    }

    /**
     * 重写堆栈填充，大多数情况不需要填充错误堆栈信息，提高性能
     */
    @Override
    public BaseException fillInStackTrace() {
        return this;
    }

}
